package oktx.feign.interceptor;

import oktx.participant.JtaParticipant;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by dave on 18-5-28 下午9:09.
 */
public class HttpRequestInterceptor implements ClientHttpRequestInterceptor {
    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        request.getHeaders().set(JtaParticipant.PRC_TRANSACTION_KEY,
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return execution.execute(request, body);
    }
}
